package swing;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Calculator implements ActionListener{
	private JFrame f;
	public Calculator(){
		initComponent();
	}
	private void initComponent() {
		f = new JFrame("My Calculator V1.0");
		f.addWindowListener(new WindowAdapter(){
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		JPanel centerPanel = new JPanel();
		centerPanel.setLayout(new GridLayout(5,3));
		String labels = "12+34-56*78/90=";
		for (int i = 0; i < labels.length(); i++) {
			JButton btn = new JButton(labels.substring(i,i+1));
			btn.addActionListener(this);
			centerPanel.add(btn);
		}
		f.add(centerPanel,BorderLayout.CENTER);
		JPanel northPanel = new JPanel();
		JTextField tf = new JTextField(30);
		northPanel.add(tf);
		f.add(northPanel,BorderLayout.NORTH);
	}
	public static void main(String[] args) {
		new Calculator().go();
	}
	private void go() {
		f.pack();//????????
		f.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		
	}
	
}
